﻿@using OA.Models.Enums
@using OA.Models.ViewModels;
@model AccountViewModel

@{
    var options = new AjaxOptions
    {
        OnBegin = "openLoading",
        OnSuccess = "ajaxSuccess"
    };
}

@using (Ajax.BeginForm("Update", "Accounts", options, new { @class = "w-form" }))
{
    @Html.ValidationSummary(false)

    <div class="w-content">
        <div class="form-table">
            @if (!Model.IsEdit)
            {
                <div class="form-tr">
                    <div class="form-td">
                        @Html.DisplayNameFor(d => d.Id)
                    </div>
                    <div class="form-td">
                        @Html.Kendo().TextBoxFor(d => d.Id)
                    </div>
                </div>
                <div class="form-tr">
                    <div class="form-td">
                        @Html.DisplayNameFor(d => d.Password)
                    </div>
                    <div class="form-td">
                        @Html.Kendo().TextBoxFor(d => d.Password).HtmlAttributes(new { type = "password" })
                    </div>
                </div>
            }
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Name)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Name)
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Gender)
                </div>
                <div class="form-td">
                    @(
                        Html.Kendo().DropDownListFor<Gender>(d => d.Gender)
                        .DataTextField("Text")
                        .DataValueField("Value")
                        .BindTo(new List<SelectListItem>()
                        {
                            new SelectListItem() {
                                Text = "保密", Value = "0"
                            },
                            new SelectListItem() {
                                Text = "男", Value = "1"
                            },
                            new SelectListItem() {
                                Text = "女", Value = "2"
                            },
                        })
                    )
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Birthday)
                </div>
                <div class="form-td">
                    @(
                        Html.Kendo().DatePickerFor(d => d.Birthday)
                        .Value(DateTime.Now)
                    )
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Email)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Email)
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Phone)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Phone)
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.PostId)
                </div>
                <div class="form-td">
                    @(
                        Html.Kendo().DropDownListFor(d => d.PostId)
                        .DataTextField("Name")
                        .DataValueField("Id")
                        .DataSource(s =>
                        {
                            s.Read(read =>
                            {
                                read.Type(HttpVerbs.Post);
                                read.Action("DropDownListRead", "Post");
                            });
                        })
                    )
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.DepartmentId)
                </div>
                <div class="form-td">
                    @(
                        Html.Kendo().DropDownListFor(d => d.DepartmentId)
                        .DataTextField("Name")
                        .DataValueField("Id")
                        .DataSource(s => {
                            s.Read(read => {
                                read.Type(HttpVerbs.Post);
                                read.Action("DropDownListRead", "Department");
                            });
                        })
                    )
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.State)
                </div>
                <div class="form-td">
                    @(
                        Html.Kendo().DropDownListFor(d => d.State)
                        .DataTextField("Text")
                        .DataValueField("Value")
                        .BindTo(new List<SelectListItem>()
                        {
                            new SelectListItem() {
                                Text = "在职", Value = "0"
                            },
                            new SelectListItem() {
                                Text = "离职", Value = "1"
                            },
                            new SelectListItem() {
                                Text = "请假", Value = "2"
                            },
                        })
                    )
                </div>
            </div>
        </div>
    </div>
    <div class="w-footer">
        @(
            Html.Kendo().Button()
            .Name("Cancel")
            .Events(e => e.Click("closeWindow"))
            .HtmlAttributes(new { type = "button" })
            .Icon("cancel")
            .Content("取消")
        )
        @(
            Html.Kendo().Button()
            .Name("Enter")
            .Icon("check")
            .Content("更新")
            .HtmlAttributes(new { @class = "k-primary" })
        )
    </div>
}

<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script>
    function ajaxSuccess(response) {
        if (response.IsSuccess) {
            $("#grid").data("kendoGrid").dataSource.read();
            closeWindow();
            openNotification(response.Message, "success");
        }
        else {
            openNotification(response.Message, "error");
        }
        closeLoading();
    }
</script>